# -*- coding: UTF-8 -*-

import os
import sys
import xeres

# Image management.

emote = None
theme = None
texture = None

# image loader
class ImageLoader(object):
	def __init__( self, prefix ):
		self.prefix = prefix.lstrip().rstrip()
		if not self.prefix.endswith( '/' ):
			self.prefix += '/'
		self.prefix = self.prefix.replace( '//' , '/' ).replace( '\\' ,  '/' )
	
	def gen( self, path ):
		return self.prefix + path
	
	def __call__( self, path ):
		fullpath = self.gen( path )
		return xeres.LoadImage( fullpath )

# state button loader
class StateButtonLoader(ImageLoader):
	def __init__( self, prefix ):
		super(StateButtonLoader,self).__init__( prefix )
	
	def __call__( self, path ):
		nml = self.gen( path.replace( '$' , '_nml' ) )
		ovr = self.gen( path.replace( '$' , '_ovr' ) )
		dwn = self.gen( path.replace( '$' , '_dwn' ) )
		dis = self.gen( path.replace( '$' , '_dis' ) )
		all = nml+';'+ovr+';'+dwn+';'+dis
		return xeres.LoadImage( all )

# Initialize all.
emote = ImageLoader( 'res/ui/emote/' )
theme = ImageLoader( 'res/ui/theme/' )
texture = ImageLoader( 'res/texture/' )
statebtn = StateButtonLoader( 'res/ui/button' )

__loaders = {}
__loaders['emote'] = emote
__loaders['theme'] = theme
__loaders['texture'] = texture
__loaders['statebtn'] = statebtn

def get_loader( name ):
	return __loaders.get(name)
